import common from './common'

const paths = {
  treeDicItemByDicName: 'dic/treeDicItemByDicName',
  listDicItemByDicName: 'dic/listDicItemByDicName',
  dictionarySearch: 'dicModel/searchDic'
}

const dicService = {};

(service => {
  /**
   * 根据字典名称获取字典项
   * @param dicName
   * @param parentId
   * @returns {Promise | Promise<unknown>}
   */
  service.listDicItemByDicName = (dicName, parentId) => {
    return common.get(paths.listDicItemByDicName, { dicName, parentId })
  }
  /**
   * 根据字典名称获取字典项
   * @param dicName
   * @param parentId
   * @returns {Promise | Promise<unknown>}
   */
  service.treeDicItemByDicName = (dicName, parentId) => {
    return common.get(paths.treeDicItemByDicName, { dicName, parentId })
  }

  service.searchDictionary = () => {
    return common.post(paths.dictionarySearch, null, {
      filterText: '',
      pageIndex: 1,
      pageSize: 9999
    })
  }
})(dicService)

export default dicService
